package open_app

import (
	"github.com/gin-gonic/gin"
	"organoid_public/global"
)

type handler struct {
	svc *service
}

func newHandler() (*handler, error) {
	svc, err := NewService()
	if err != nil {
		return nil, err
	}
	return &handler{svc: svc}, nil
}

// 应用检测
func (h *handler) discernApp(c *gin.Context) {
	var (
		params   DiscernReq
		response = global.Response.New(c)
	)
	err := response.BindWithValidate(&params)
	if err != nil {
		return
	}
	res, err := h.svc.discernApp(params.OpenAppId)
	if err != nil {
		response.Error(err).ToJSON()
		return
	}
	c.Set("OpenId", res.Id)
	c.Set("OpenAppId", res.OpenAppId)

}
